home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / AmigaTalk / user / SqMatrix.st < prev    next >
Text File  |  2004-01-31  |  1KB  |  49 lines

  1. " -------------------------------------------------------------- "
  2. " SqMatrix.st - Implementation of Square Matrices for AmigaTalk. "
  3. " -------------------------------------------------------------- "
  4.  
  5. Class SqMatrix :Magnitude ! size ele !
  6. [
  7.   new: newSize
  8.     (newSize < 2)
  9.        ifTrue: [ ('size of SqMatrix too small!') print. 
  10.                  ^ nil
  11.                ].
  12.        
  13.     size <- newSize. 
  14.     ele  <- Array new: (size * size).
  15.  
  16.     (1 to: (size * size)) do: [:i | ele at: i put: (Float new: 0.0)].
  17.  
  18.     ^ self
  19. |
  20.   scale: s
  21.     (1 to: (size * size)) do: [:i | ele at: i put: (s * (ele at: i))].
  22.     ^ self 
  23. |
  24.   getElementAt: rcPoint ! idx !
  25.     ((rcPoint x) < 1 | (rcPoint y) < 1)
  26.       ifTrue:  [ ('Row@Column below minimum(1) in SqMatrix.') print.
  27.                  ^ nil
  28.                ].
  29.       
  30.     idx <- (size * ((rcPoint x) - 1) + rcPoint y).
  31.  
  32.     ^ ele at: idx
  33. |
  34.   setElement: val at: rcPoint ! idx !
  35.     ((rcPoint x) < 1 | (rcPoint y) < 1)
  36.       ifTrue:  [ ('Row@Column below minimum(1) in SqMatrix.') print.
  37.                  ^ nil
  38.                ].
  39.  
  40.     ((rcPoint x) > size | (rcPoint y) > size)
  41.       ifTrue:  [ ('Row@Column > size in SqMatrix.') print.
  42.                  ^ nil
  43.                ].
  44.  
  45.     idx <- (size * ((rcPoint x) - 1) + rcPoint y).
  46.     ele at: idx put: val.
  47.     ^ self
  48. ]
  49.